<template>
  <div class="wrapper">
    <!-- header部分 -->
    <header>
      <p>在线支付</p>
    </header>

    <!-- 订单信息部分 -->
    <h3>订单信息：</h3>
    <div class="order-info">
      <p>
        万家饺子（软件园E18店）
        <i
            class="fa"
            :class="showDetails ? 'fa-caret-up' : 'fa-caret-down'"
            @click="toggleDetails"
        ></i>
      </p>
      <p>&#165;{{ totalPrice }}</p>
    </div>

    <!-- 订单明细部分 -->
    <ul class="order-detailet" v-show="showDetails">
      <li v-for="(item, index) in orderItems" :key="index">
        <p>{{ item.name }} x {{ item.quantity }}</p>
        <p>&#165;{{ item.price * item.quantity }}</p>
      </li>
      <li>
        <p>配送费</p>
        <p>&#165;{{ deliveryFee }}</p>
      </li>
    </ul>

    <!-- 支付方式部分 -->
    <ul class="payment-type">
      <li @click="selectPayment('alipay')">
        <img src="/img/alipay.png" alt="支付宝">
        <i class="fa fa-check-circle" v-show="selectedPayment === 'alipay'"></i>
      </li>
      <li @click="selectPayment('wechat')">
        <img src="/img/wechat.png" alt="微信支付">
        <i class="fa fa-check-circle" v-show="selectedPayment === 'wechat'"></i>
      </li>
    </ul>
    <div class="payment-button">
      <button @click="confirmPayment">确认支付</button>
    </div>

    <!-- 底部菜单部分 -->
    <FooterNav />
  </div>
</template>

<script setup lang="ts">
import {computed, ref} from 'vue';
import { useRouter } from 'vue-router';
import FooterNav from '@/components/FooterNav.vue';

interface OrderItem {
  id: number;
  name: string;
  price: number;
  quantity: number;
}


// 配送费
const deliveryFee = ref(3);

// 订单明细数据
const orderItems = ref<OrderItem[]>([
  { id: 1, name: '纯肉鲜肉（水饺）', price: 15, quantity: 2 },
  { id: 2, name: '玉米鲜肉（水饺）', price: 16, quantity: 1 }
]);

// 计算总价格（商品总价 + 配送费）
const totalPrice = computed(() => {
  const itemsTotal = orderItems.value.reduce((sum, item) => sum + (item.price * item.quantity), 0);
  return itemsTotal + deliveryFee.value;
});

// 是否显示订单详情
const showDetails = ref(false);

// 切换订单详情显示状态
const toggleDetails = () => {
  showDetails.value = !showDetails.value;
};

// 选择的支付方式
const selectedPayment = ref('alipay');

// 选择支付方式
const selectPayment = (payment: string) => {
  selectedPayment.value = payment;
};

// 确认支付
const confirmPayment = () => {
  alert('支付成功！');
};


</script>

<style scoped>
/* 总容器 */
.wrapper {
  width: 100%;
  height: 100%;
  padding-bottom: 14vw; /* 为底部菜单留出空间 */
}

/* header部分 */
header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 12vw;
  background-color: #0097FF;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  font-size: 4.5vw;
  z-index: 100;
}

/* 订单信息部分 */
h3 {
  margin-top: 12vw;
  box-sizing: border-box;
  padding: 4vw 4vw 0;
  font-size: 4vw;
  font-weight: 300;
  color: #999;
}

.order-info {
  box-sizing: border-box;
  padding: 4vw;
  font-size: 4vw;
  color: #666;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.order-info p:last-child {
  color: orangered;
}

/* 订单明细部分 */
.order-detailet {
  width: 100%;
}

.order-detailet li {
  width: 100%;
  box-sizing: border-box;
  padding: 1vw 4vw;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.order-detailet li p {
  font-size: 3vw;
  color: #666;
}

/* 支付方式部分 */
.payment-type {
  width: 100%;
}

.payment-type li {
  width: 100%;
  box-sizing: border-box;
  padding: 4vw;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.payment-type li img {
  width: 33vw;
  height: 8.9vw;
}

.payment-type li .fa-check-circle {
  font-size: 5vw;
  color: #38CA73;
}

.payment-button {
  width: 100%;
  box-sizing: border-box;
  padding: 4vw;
}

.payment-button button {
  width: 100%;
  height: 10vw;
  border: none;
  outline: none;
  border-radius: 4px;
  background-color: #38CA73;
  color: #fff;
  font-size: 4.5vw;
  cursor: pointer;
}



.footer li {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #999;
  user-select: none;
  cursor: pointer;
}

.footer li p {
  font-size: 2.8vw;
}

.footer li i {
  font-size: 5vw;
}
</style>
